Break/continue in a foreach loop Powershell – Azurepowershell.com 您所在的位置:网站首页 powershell ForEach-Object break Break/continue in a foreach loop Powershell – Azurepowershell.com

Break/continue in a foreach loop Powershell – Azurepowershell.com

2024-04-13 12:29| 来源: 网络整理| 查看: 265

How to use break and continue in a foreach loop in Powershell

1234567891011121314151617181920212223242526# Use break to get out of the loop $files = Get-ChildItem C:\PSfolder -File foreach ($file in $files) {   if ($file.Name -like "*.ps1")   {     $file.Name     break  # exit the foreach loop   } } # Use continue to skip the rest of a loop but go onto the next iteration $files = Get-ChildItem C:\PSfolder -File foreach ($file in $files) {   if ($file.Name -like "*.ps1")   {     $file.Name     continue  # exit and go tho the next item in foreach     "This code will be skipped"   }   "This isn't a powershell file: $file" }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有